package com.cxria.shiro.shiro.filter;

import com.cxria.shiro.entity.SUser;
import com.cxria.shiro.service.ShiroUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.filter.PathMatchingFilter;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class SysUserFilter extends PathMatchingFilter {

	@Autowired
	private ShiroUserService userService;

	@Override
	protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue)
			throws Exception {
		String username = (String) SecurityUtils.getSubject().getPrincipal();
		SUser user = userService.getByUsername(username);
		request.setAttribute("user", user);
		return true;
	}

}
